package com.mpgame.database.redis.manager;

import com.mpgame.database.redis.config.RedisCfg;
import com.mpgame.database.redis.utils.RedisUtil;
import com.mpgame.utils.Log;

public class RedisMgr {
    private static volatile RedisMgr instance;
    private static volatile boolean initialized = false;

    private RedisMgr(){}

    public static RedisMgr getInstance(){
        if(instance == null){
            synchronized (RedisMgr.class){
                if(instance == null){
                    instance = new RedisMgr();
                }
            }
        }
        return instance;
    }

    public void init(RedisCfg cfg){
        if(initialized){
            Log.warn("Redis连接池已初始化完成，不可重复初始化！");
            return;
        }
        RedisUtil.init(cfg);
        initialized = true;
        Log.info("Redis管理器初始化完成");
    }
    public void init(){
        init(RedisCfg.getDefault());
    }

    public void shutdown(){
        if(initialized){
            RedisUtil.close();
            initialized = false;
            Log.info("Redis管理器已关闭");
        }
    }

    public boolean isInitialized(){
        return initialized;
    }
}
